﻿using System;
using System.Collections.Generic;

using E.BLL;
using E.Model;
using E.Web.UI.Page;

using X.Common;


namespace E.Web.training.internals.classes
{
    public partial class SignUp : BasePage
    {
        protected override void ShowPage()
        {
            if (ispost)
            {
                int classid = XRequest.GetInt("classid", -1);
                int courseid = XRequest.GetInt("courseid", -1);
                int projectid = XRequest.GetInt("projectid", -1);
                int signuptypeid = XRequest.GetInt("signuptypeid", -1);
                string isFreeCourse = XRequest.GetString("isFreeCourse");
                int rst = 0;
                if (isFreeCourse == null || isFreeCourse.Equals(""))
                {
                    if (classid != -1 && courseid != -1 && projectid != -1)
                    {
                        rst = (new ClassBLL()).SignUpInternal(userid, classid, courseid, projectid, signuptypeid);
                        SignUpResult(rst);
                    }
                    else
                    {
                        ExecuteJS("alert('参数错误'); history.back();");
                    }
                }
                else if (isFreeCourse == "true")
                {
                    if (courseid != -1 && projectid != -1)
                    {
                        rst = (new CourseBLL()).SignUpInternalFreeCourse(userid, courseid, projectid);
                        SignUpResult(rst);
                    }
                    else
                    {
                        ExecuteJS("alert('参数错误'); history.back();");
                    }
                    
                }
                
            }
        }

        private void SignUpResult(int rst)
        {
            if (rst > 0)
            {
                ExecuteJS("alert('报名成功'); history.back();");
            }
            else
            {
                ExecuteJS("alert('报名失败或已报过该项目'); history.back();");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
